import collections
class MovingAverage(object):

    def __init__(self, size):
        """
        :type size: int
        """
        self.size = size
        self.c = [0] * self.size
        self.state = 0

    def next(self, val):
        """
        :type val: int
        :rtype: float
        """
        self.c[self.state % self.size] = val
        self.state += 1
        count = self.state if self.state < self.size else self.size
        return sum(self.c) / count